<div class="panel panel-default panel-intro">
    <div class="panel-heading">
        <ul class="nav nav-tabs" data-field="status">
            <li class="active"><a href="#trigger-tab" data-toggle="tab">手动触发返利</a></li>
        </ul>
    </div>
    <div class="panel-body">
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade active in" id="trigger-tab">
                <div class="widget-body no-padding">
                    
                    <!-- 状态检查区域 -->
                    <!-- <div class="alert alert-info">
                        <h4><i class="fa fa-info-circle"></i> 返利触发条件检查</h4>
                        <div id="condition-info">
                            <button type="button" class="btn btn-info" id="check-condition">检查触发条件</button>
                        </div>
                    </div> -->
                    
                    <!-- 触发区域 -->
                    <div class="alert ">
                        <h4> 手动触发返利</h4>
                        <p>点击按钮将手动触发一次返利操作，此操作不受利润条件限制。</p>
                        <br/>
                        <form id="trigger-form" method="post" action="{:url('rebate/batches/trigger')}">
                            <button type="submit" class="btn btn-warning btn-lg" id="trigger-btn">
                                <i class="fa fa-rocket"></i> 立即触发返利
                            </button>
                        </form>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
</div>

<script>
$(document).ready(function() {
    // 检查触发条件
    $('#check-condition').click(function() {
        $.ajax({
            url: '{:url("")}',
            type: 'GET',
            success: function(response) {
                if (response.code === 1) {
                    var data = response.data;
                    var html = '<table class="table table-bordered">' +
                               '<tr><td>当前总利润</td><td>' + data.current_profit + '</td></tr>' +
                               '<tr><td>触发所需利润</td><td>' + data.required_profit + '</td></tr>' +
                               '<tr><td>下一期数</td><td>' + data.next_period + '</td></tr>' +
                               '<tr><td>是否可触发</td><td>' + (data.can_trigger ? '<span class="text-success">是</span>' : '<span class="text-danger">否</span>') + '</td></tr>' +
                               '</table>';
                    $('#condition-info').html(html);
                } else {
                    Toastr.error(response.msg);
                }
            },
            error: function() {
                Toastr.error('检查失败');
            }
        });
    });
    
    // 触发确认
    $('#trigger-form').submit(function(e) {
        if (!confirm('确定要手动触发返利吗？此操作不可逆！')) {
            e.preventDefault();
            return false;
        }
    });
});
</script>